from rest_framework.response import Response


class APIResponse(Response):
    def __init__(self, code=100, msg='successfully', data=None, status=None,
                 template_name=None, headers=None,
                 exception=False, content_type=None, **kwargs):
        dic = {'status': code, 'msg': msg}
        if data:  # 如果data有值，说明要往里面放东西
            dic['data'] = data
        if kwargs:  # 自定义传的参数会添加到字典里
            dic.update(kwargs)

        super().__init__(data=dic, status=status,
                         template_name=template_name, headers=headers,
                         exception=exception, content_type=content_type)
